
import torch

def rand(size):
	return torch.randn(size,size)

def split(m1, m2, blocks):
	size = m1.size(0)
	assert size % blocks == 0
	b_size = size // blocks
	m1 = torch.randn(size,size)
	m2 = torch.randn(size,size)
	ms = [(m1[i*b_size:(i+1)*b_size, :], 
				m2[:, j*b_size:(j+1)*b_size]) 
				for i in range(blocks)
				for j in range(blocks)]
	return ms

def merge(mats, blocks):
	mats = [torch.cat(mats[i*blocks:(i+1)*blocks], dim=1)
			for i in range(blocks)]
	return torch.cat(mats, dim=0)
